package com.jy.rhin.domain.notification.receive;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.jy.rhin.domain.notification.receive.entity.ReceiveMessageDO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author dhl
 * @date 2022/6/28
 * @Description
 */
@Service
public class ReceiveMessageDomainService {

    @Resource
    private ReceiveMessageDao receiveMessageDao;

    /**
     * 先校验消息幂等
     * 再存储消息数据
     * @param receive
     * @return
     */
    public Long receive(ReceiveMessageDO receive){

        //幂等
        ReceiveMessageDO data = receiveMessageDao.queryByMsgId(receive.getMsgId());
        if (ObjectUtils.isNull(data)) {
            return receiveMessageDao.receive(receive);
        } else {
            return data.getId();
        }
    }
}
